/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.hugo.senai.view;


import br.com.hugo.senai.classes.Configuracoes;
import br.com.hugo.senai.entities.Conteudo;
import br.com.hugo.senai.entities.Curso;
import br.com.hugo.senai.entities.Disciplina;
import br.com.hugo.senai.dao.Hibernate;
import java.util.List;

/**
 *
 * @author Simulado
 */
public class CadastroConteudo extends javax.swing.JFrame {

    /**
     * Creates new form CadastroConteudo
     */
    public CadastroConteudo() {
        initComponents();
         super.setTitle(new Configuracoes().SYSTEM_NAME+super.getTitle());
        this.setIconImage(new Configuracoes().SYSTEM_ICON);
        cbQuestaoCurso.removeAllItems();
        List <Curso> cursos = Hibernate.listAll(Curso.class);
        for (Curso curso : cursos){
            cbQuestaoCurso.addItem(curso);
            
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        tfNomeConteudo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cbQuestaoCurso = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cbConteudo = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        tfNomeConteudo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNomeConteudoActionPerformed(evt);
            }
        });

        jLabel1.setText("Nome:");

        cbQuestaoCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbQuestaoCursoActionPerformed(evt);
            }
        });

        jLabel7.setText("CURSO:");

        jLabel8.setText("Selecione a disciplina:");

        cbConteudo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbConteudoMouseClicked(evt);
            }
        });
        cbConteudo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbConteudoActionPerformed(evt);
            }
        });

        jLabel2.setText("Cadastro conteúdo");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(12, 12, 12))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbQuestaoCurso, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(0, 136, Short.MAX_VALUE))
                    .addComponent(cbConteudo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(tfNomeConteudo))
                .addGap(70, 70, 70))
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(tfNomeConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cbQuestaoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(cbConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap(74, Short.MAX_VALUE))
        );

        setSize(new java.awt.Dimension(439, 243));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       Conteudo c = new Conteudo();
       c.setNome(tfNomeConteudo.getText());
       c.setDisciplina((Disciplina) cbConteudo.getSelectedItem());

       Hibernate.save(c);
 
       
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cbQuestaoCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbQuestaoCursoActionPerformed
        cbConteudo.removeAllItems();

        List<Disciplina> materias = Hibernate.listAll(Disciplina.class, (Curso) cbQuestaoCurso.getSelectedItem(), "curso");

        for (Disciplina materia : materias) {
            cbConteudo.addItem(materia);
        }
    }//GEN-LAST:event_cbQuestaoCursoActionPerformed

    private void cbConteudoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbConteudoMouseClicked

    }//GEN-LAST:event_cbConteudoMouseClicked

    private void cbConteudoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbConteudoActionPerformed
//        cbQuestaoConteudo.removeAllItems();
//
//        List<Conteudo> conteudos = Hibernate.listAll(Conteudo.class, (Disciplina) cbConteudo.getSelectedItem(), "disciplina");
//
//        for (Conteudo conteudo : conteudos) {
//            cbQuestaoConteudo.addItem(conteudo);
//        }
    }//GEN-LAST:event_cbConteudoActionPerformed

    private void tfNomeConteudoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNomeConteudoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfNomeConteudoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroConteudo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroConteudo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroConteudo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroConteudo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CadastroConteudo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbConteudo;
    private javax.swing.JComboBox cbQuestaoCurso;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField tfNomeConteudo;
    // End of variables declaration//GEN-END:variables
}
